package cn.kinoko.controller.user;

import cn.kinoko.common.base.model.BaseController;
import cn.kinoko.common.base.model.Result;
import cn.kinoko.model.user.entity.UserInfo;
import cn.kinoko.model.user.req.PassChangeReq;
import cn.kinoko.model.user.req.UserInfoUpdateReq;
import cn.kinoko.service.common.util.AuthUtil;
import cn.kinoko.service.user.UserInfoService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author kinoko
 */
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Resource
    private UserInfoService userInfoService;

    @GetMapping("/current")
    public Result<UserInfo> currentUserInfo() {
        return success(AuthUtil.getCurrentUser());
    }

    @PostMapping("/updateInfo")
    public Result<Object> updateInfo(@RequestBody @Validated UserInfoUpdateReq req) {
        return toAjax(userInfoService.update(AuthUtil.getCurrentUser(), req));
    }

    @PostMapping("/changePass")
    public Result<Object> changePass(@RequestBody PassChangeReq req) {
        return toAjax(userInfoService.changePass(req));
    }

}
